﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.Mvc;

namespace WebShop.Common
{
    public static class MenuHelper
    {
        public static string Menu()
        {
            var sb = new StringBuilder();
            GetSubmenu(sb, SiteMap.RootNode);
            return sb.ToString();
        }

        private static void GetSubmenu(StringBuilder sb, SiteMapNode parentNode)
        {

            if (parentNode.ParentNode == null)
            {
                sb.Append("<ul class='dropdown'>");
            }
            else
            {
                sb.Append("<ul class='menu'>");
            }

            foreach (SiteMapNode node in parentNode.ChildNodes)
            {
                if (node.HasChildNodes)
                {
                    sb.AppendLine("<li class='dir'>");
                    GetSubmenu(sb, node);
                }
                else
                {
                    sb.AppendLine("<li>");
                }
                
                sb.AppendFormat("<a href='{0}'>{1}</a>", "http://www.google.com", node.Title);
                sb.AppendLine("</li>");
            }

            sb.Append("</ul>");
            return;
        }

    }
}